package com.csair.seam.domain.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csair.seam.domain.mapper.VehicleLossStatisticsMapper;
import com.csair.seam.domain.model.entity.VehicleLossStatistics;
import com.csair.seam.domain.model.vo.VehicleLossChartVo;
import com.csair.seam.domain.model.vo.VehicleLossStatisticsVo;
import com.csair.seam.domain.service.IVehicleLossStatisticsService;

/**
 * @description 车辆损耗统计service接口实现类
 * @author lanrunli
 *
 */
@Service
public class VehicleLossStatisticsServiceImpl extends ServiceImpl<VehicleLossStatisticsMapper, VehicleLossStatistics> implements IVehicleLossStatisticsService {

	@DS("nc63")
	@Override
	public VehicleLossStatisticsVo findVehicleLossData() {
		Map<String, VehicleLossChartVo> map = new HashMap<>();
		List<VehicleLossStatistics> generalVehicleLoss = getBaseMapper().findVehicleLoss("11");//通用车辆数据
		for (VehicleLossStatistics vehicleLossStatistics : generalVehicleLoss) {
			VehicleLossChartVo chartVo = new VehicleLossChartVo();
			chartVo.setOrgName(vehicleLossStatistics.getOrgName());
			chartVo.setGeneralRuntimeDataRate(vehicleLossStatistics.getRuntimeDataRate());
			map.put(vehicleLossStatistics.getOrgCode(), chartVo);
		}
		
		List<VehicleLossStatistics> specialVehicleLoss = getBaseMapper().findVehicleLoss("12");//特种车辆数据
		for (VehicleLossStatistics vehicleLossStatistics : specialVehicleLoss) {
			if(map.containsKey(vehicleLossStatistics.getOrgCode())) {
				VehicleLossChartVo chartVo = map.get(vehicleLossStatistics.getOrgCode());
				chartVo.setSpecialRuntimeDataRate(vehicleLossStatistics.getRuntimeDataRate());
			}else {
				VehicleLossChartVo chartVo = new VehicleLossChartVo();
				chartVo.setOrgName(vehicleLossStatistics.getOrgName());
				chartVo.setSpecialRuntimeDataRate(vehicleLossStatistics.getRuntimeDataRate());
				map.put(vehicleLossStatistics.getOrgCode(), chartVo);
			}
			
		}
		
		VehicleLossStatisticsVo vo = new VehicleLossStatisticsVo();
		vo.setGeneralVehicleLoss(generalVehicleLoss);
		vo.setSpecialVehicleLoss(specialVehicleLoss);
		vo.setVehicleLossChartMap(map);
		return vo;
	}

	@DS("nc63")
	@Override
	public List<VehicleLossStatistics> getGeneralVehicleLoss() {
		return getBaseMapper().findVehicleLoss("11");//通用车辆数据
	}

	@DS("nc63")
	@Override
	public List<VehicleLossStatistics> getSpecialVehicleLoss() {
		return getBaseMapper().findVehicleLoss("12");//特种车辆数据
	}


}
